<template>
  <div>
    <!-- 面包屑区域 -->
    <Breadcrumb></Breadcrumb>
    <el-card>
      <el-row>
        <el-col :span="8">
          <!-- 搜索区域 -->
          <el-input placeholder="请输入内容">
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表单区域 -->
      <el-table :data="orderData" stripe border style="width: 100%">
        <el-table-column type="index" label="#" width="50"></el-table-column>
        <el-table-column prop="order_number" label="订单编号"></el-table-column>
        <el-table-column prop="order_price" label="订单价格"></el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
          <template slot-scope="scope">
            <el-tag type="success" v-if="scope.row.pay_status == '1'"
              >已付款</el-tag
            >
            <el-tag type="danger" v-else>未付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"> </el-table-column>
        <el-table-column label="下单时间">
          <template slot-scope="scope">
            {{ scope.row.create_time | datrfmt("YYYY-MM-DD HH:mm:ss") }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template>
            <el-button
              type="primary"
              size="mini"
              icon="el-icon-edit"
              @click="showBox"
            ></el-button>
            <el-button
              type="success"
              size="mini"
              icon="el-icon-location"
              @click="showProgressBox"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page.sync="queryInfo.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="queryInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
    <!-- 编辑对话框 -->
    <el-dialog
      title="修改地址"
      :visible.sync="showBoxDialog"
      width="50%"
      @close="editDialogClose"
    >
      <el-form
        :model="editForm"
        :rules="editFormRules"
        ref="editFormRef"
        label-width="100px"
      >
        <el-form-item label="省市区/县" prop="location">
          <el-cascader
            :options="cityData"
            v-model="editForm.location"
            clearable
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="detailedAddr">
          <el-input v-model="editForm.detailedAddr"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="showBoxDialog = false">取 消</el-button>
        <el-button type="primary" @click="showBoxDialog = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 展示物流进度的对话框 -->
    <el-dialog title="物流进度" :visible.sync="progressVisible" width="50%">
      <el-timeline >
        <el-timeline-item
          v-for="(activity, index) in rogData"
          :key="index"
          :timestamp="activity.time"
          icon='el-icon-location'
          type='success'
        >
          {{ activity.context }}
        </el-timeline-item>
      </el-timeline>
      <span slot="footer" class="dialog-footer">
        <el-button @click="progressVisible = false">取 消</el-button>
        <el-button type="primary" @click="progressVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import Breadcrumb from "../Breadcrumb";
import cityData from "../order/citydata";
export default {
  components: {
    Breadcrumb,
  },
  data() {
    return {
      queryInfo: {
        query: "",
        pagenum: 1,
        pagesize: 5,
      },
      total: 0,
      orderData: [],
      showBoxDialog: false,
      //   修改表单
      editForm: {
        location: [],
        detailedAddr: "",
      },
      //   验证规则
      editFormRules: {
        location: [
          { required: true, message: "请选择省市区县", trigger: "blur" },
        ],
        detailedAddr: [
          { required: true, message: "请填写详细地址", trigger: "blur" },
        ],
      },
      // 省市区县数据
      cityData,
      //   进度对话框开关
      progressVisible: false,
      rogData: [],
    };
  },
  created() {
    this.getOrderData();
  },
  methods: {
    async getOrderData() {
      let { data: res } = await this.$http.get("orders", {
        params: this.queryInfo,
      });
      console.log(res);
      if (res.meta.status !== 200) return this.$message.error("获取数据失败！");
      this.orderData = res.data.goods;
      this.total = res.data.total;
    },
    handleSizeChange(val) {
      this.queryInfo.pagesize = val;
      this.getOrderData();
    },
    handleCurrentChange(val) {
      this.queryInfo.pagenum = val;
      this.getOrderData();
    },
    // 编辑按钮事件
    showBox() {
      this.showBoxDialog = true;
    },
    // 编辑对话框关闭的回调
    editDialogClose() {
      this.$refs.editFormRef.resetFields();
    },
    // 进度条 对话框打开的事件
    async showProgressBox() {
      let { data: res } = await this.$http.get("/kuaidi/804909574412544580");
      if (res.meta.status !== 200)
        return this.$message.error("获取物流进度失败！");
      this.rogData = res.data;
      console.log(this.rogData);
      this.progressVisible = true;
    },
  },
};
</script>
<style lang="scss" scoped>
.el-table {
  margin: 15px 0px;
}
.el-cascader {
  width: 100%;
}
</style>